package com.ms.game.common;

import java.util.ArrayList;

import com.ms.game.common.container.LevelInfoBin;
import com.ms.game.common.container.LevelUpInfo;
import com.ms.player.Player;
import com.xpec.c4.game.utility.GameUtility;

public class PlayerLimitInfo 
{
	/**
	 * 沒有找到服務費的VIP資料
	 */
	public static final int NOT_FOUND_CHARG = -1;
	
	
	/**
	 * 讀取VIP經驗值上限
	 * @return
	 * @deprecated
	 */
	public static long getLimitForDeposit(Player player)
	{
		LevelUpInfo vip = getVipInfo(player);
		if(vip==null)
		{
			return 0;
		}
		
		return vip.getNeedExp();
	}
	
	/**
	 * 讀取保留資料([0]=台數 [1]=時間)
	 * @return
	 * @deprecated
	 */
	public static int [] getLimitKeepInfo(Player player)
	{
		LevelUpInfo vip = getVipInfo(player);
		if(vip==null)
		{
			return new int[]{0,0};
		}
		return new int[]{vip.getKeepcount(),(int)vip.getKeeptime()};
	}
	/**
	 * 讀取離線保留資料([0]=台數 [1]=時間)
	 * @param player
	 * @return
	 * @deprecated
	 */
	
	public static int[] getOfflineKeepTime(Player player)
	{
		LevelUpInfo vip = getVipInfo(player);
		if(vip==null)
		{
			return new int[]{0,0};
		}
		return new int[]{1,(int)vip.getOfflinekeeptime()};
	}
	
	
	/**
	 * 公開or 不公開群組資料([0]=群組數 [1]=群組最大人數)
	 * @return
	 * @deprecated
	 */
	public static int [] getChannlInfo(VIPandLVLimitType type,Player player)
	{
		LevelUpInfo vip = getVipInfo(player);
		if(vip==null)
		{
			return new int[]{0,0};
		}
		
		int [] data = null;
		if(type.getID() == VIPandLVLimitType.CHANNEL_PRIVATE_GROUP.getID())
		{
			data = new int[]{vip.getMaxPrivateCreateGroupCount() , vip.getMaxPrivateGroupMemberCount()};
		}
		else  if(type.getID() == VIPandLVLimitType.CHANNEL_PUBLIC_GROUP.getID())
		{
			data =new int[]{vip.getMaxCreateGroupCount() , vip.getMaxGroupMemberCount()};
		}
		else
		{
			return new int[]{0,0};
		}
		
		return data;
	}
	
	/**
	 * 是否可使用道具
	 * @return
	 */
	public static boolean useItem(Player player)
	{
		LevelUpInfo vip = getVipInfo(player);
		if(vip==null)
		{
			return false;
		}
		return vip.isUseitem();
	}
	
	/**
	 * 交易 - 轉入
	 * @return
	 */
	public static boolean canTransIN(Player player)
	{
		LevelUpInfo vip = getVipInfo(player);
		if(vip==null)
		{
			return false;
		}
		
		return  vip.isTransin();
	}
	
	/**
	 * 交易 - 轉出
	 * @return
	 */
	public static boolean canTransOut(Player player)
	{
		LevelUpInfo vip = getVipInfo(player);
		if(vip==null)
		{
			return false;
		}
		
		return  vip.isTransout();
	}
	
	/**
	 * 交易手續費
	 * @return
	 */
	public static int transCharge(Player player)
	{
		LevelUpInfo vip = getVipInfo(player);
		if(vip==null)
		{
			return NOT_FOUND_CHARG;
		}
		
		
		return vip.getTranscharge();
	}
	
	/**
	 * 尋找合適玩家的vipinfo
	 * @param player
	 * @return
	 */
	public static LevelUpInfo getVipInfo(Player player)
	{
		LevelUpInfo info = null;
		if(GameUtility.isHaveString(player.getUplineCode())&&player.getVip() == 0){
			info = getVipInfo(1, player.getLevel());
		}else{
			info = getVipInfo(player.getVip(), player.getLevel());
		}

		return info;
	}
	
	
	public static LevelUpInfo getVipInfo(int playervip , int playerlv)
	{
		int vip = playervip;
		int lv = playerlv;
		
		ArrayList<LevelUpInfo> vipinfo = LevelInfoBin.getInstance().getVipLevelUpInfoList();
		
		if(vip==0)
		{
			return vipinfo.get(0);
		}
		
		LevelUpInfo info = null;
		for(LevelUpInfo vv:vipinfo)
		{
			if(vip>=vv.getLevel() || lv>=vv.getPlayerlv())
			{
				info = vv;
			}
		}
		
		return info;
	}
	
	
	/**
	 * 玩家押注額
	 * @param name
	 * @param totalbet
	 * @return
	 */
	public static int getMaxBet(int lv)
	{
		if(lv == 0)
		{
			return 1;
		}
		
		return  (lv>20)? 20:lv;
	}
	
}
